import { createSvgIconsPlugin } from 'vite-plugin-svg-icons'
import path from 'path'

// https://github.com/vbenjs/vite-plugin-svg-icons
/**
 * src/assets/svg
 * - icon1.svg  => <SvgIcon name="icon1"></SvgIcon> =>
 * - dir/icon1.svg => <SvgIcon name="dir-icon1"></SvgIcon>
 */
export default function svgIconPlugin(isBuild: boolean) {
  return createSvgIconsPlugin({
    iconDirs: [path.resolve(process.cwd(), 'src/assets/svg')],
    symbolId: 'svg-[dir]-[name]',
    svgoOptions: isBuild, // 开启压缩
    customDomId: '__svg_icons__',
    inject: 'body-last',
  })
}
